<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<form id="myform" action="#" method="post">
    书名:<input type="text" id="bookName"><br>
    作者:<input type="text" id="bookAuthor"><br>
    价格:<input type="text" id="bookPrice "><br>
    图片:<input type="text" id="bookImg"><br>
    日期:<input type="date" id="bookDate"><br>
    描述:<input type="text" id="bookDesc"><br>
    <input type="button" value="修改图书" id="upBook">
    <input type="button" value="返回" onclick="history.back()">
</form>
<script src="js/jq.js"></script>
<script>
    $(function () {
        var id = localStorage.getItem("id");
        $.ajax({
            url:"http://localhost:8081/book/query",
            data:{
                bookId: id
            },
            success(res){
                //console.log(res);
                $('#bookName').val(res.bookName);
                $('#bookAuthor').val(res.bookAuthor);
                $('#bookPrice').val(res.bookPrice);
                $('#bookImg').val(res.bookImg);
                $('#bookDate').val(res.bookDate);
                $('#bookDesc').val(res.bookDesc);
            }
        });
        $('#upBook').click(function (){
            //封装数据发后端
            var obj={
                bookId: id,
                bookName:$('#bookName').val(),
                bookAuthor:$('#bookAuthor').val(),
                bookPrice:$('#bookPrice').val(),
                bookImg:$('#bookImg').val(),
                bookDate:$('#bookDate').val(),
                bookDesc:$('#bookDesc').val()
            }
            $.ajax({
                url:"http://localhost:8081/book/update",
                data:obj,
                success(){
                    location.href="queryBook.html";
                }
            });
        })
    })
</script>